<template>
	<view>
		<view class="question-list-title" style="color: #A2A2A2;">
			<text>关于 &nbsp;<text style="color: #000000;font-weight: bold;">{{questionTitle}}</text>&nbsp; 的<text style="color: #E53636;">{{questions.length}}</text>个问题</text>
		</view>
		<view v-for="(item,index) in questions" :key="index" class="border-bottom" style="font-size: 28upx;padding: 36upx 0upx; margin: 0 40upx;">
			<view class="d-flex j-sb" style="line-height: 60upx;">
				<view class="d-flex a-center">
					<uni-tag text="问" size="small" type="error" style="margin-right: 20upx;"></uni-tag>
					<text style="color: #2A2A2A;">{{item.content}}</text>
				</view>
			</view>
			<view class="d-flex a-center" v-if="item.questionList.length > 0" style="line-height: 60upx;">
				<uni-tag text="答" size="small" type="success" style="margin-right: 20upx;"></uni-tag>
				<text style="color: #2A2A2A;">{{item.questionList[0].content}}</text>
			</view>
			<view class="d-flex j-sb">
				<text style="color: #E53636;" @click="skipToAnswerDetail(item)">查看{{item.questionList.length}}个回答</text>
				<text style="color: #999999;">{{item.date}}</text>
			</view>
		</view>
		<view class="more-info-module" @tap="startQuestion()">
			<image src="../../../static/images/estate/question.png" style="width: 26upx;height: 26upx;" mode=""></image>
			<text style="margin-left: 10upx;">我要提问</text>
		</view>
		<!-- 评论框 -->
		<view class="mask" ref="maskNode" :style="'top:' + maskTop + 'px;'" v-show="commentAreaVisible">
			<view class="comment-area d-flex a-center border-top j-sb">
				<input class="comment-input" v-model="questionContent" type="text">
				<view class="comment-btn" @tap="saveQuestion()">
					<text>提问</text>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import api from '@/common/lib/request.js';
	import uniTag from "@/components/uni-ui/uni-tag/uni-tag.vue";
	export default {
		data() {
			return {
				token: '',
				contentId: 0,
				maskTop: 0,
				questions: [],
				questionTitle: "",
				commentAreaVisible: false,
				questionContent:""
			}
		},
		components: {
			uniTag
		},
		onLoad(options) {
			let sysInfo = uni.getSystemInfoSync();
			this.maskTop = sysInfo.windowTop;
			console.log(sysInfo)
			if (options.contentId) {
				this.contentId = options.contentId;
				this.questionTitle = options.title;
				uni.setNavigationBarTitle({
					'title': options.title + "的相关问题"
				})
			}
		},
		onShow(){
			this.token = uni.getStorageSync('token');
			this.getQuestionList();
		},
		methods: {
			getQuestionList() {
				let _this = this;
				api.request({
						url: '/lpxx/questions',
						data: {
							contentId: _this.contentId
						}
					})
					.then(response => {
						console.log(response)
						this.questions = response;
					})
					.catch(err => {
						console.log(err);
					});
			},
			skipToAnswerDetail(questionList) {
				uni.navigateTo({
					url: "/pages/estate/questionList/questionDetail/questionDetail?questions=" + encodeURIComponent(JSON.stringify(
						questionList)) + "&contentId=" + this.contentId
				})
			},
			startQuestion(){
				this.commentAreaVisible = true;
				this.questionContent = "";
			},
			// 保存提问信息
			saveQuestion(){
				let _this = this;
				api.request({
						url: '/lpxx/question/save',
						data: {
							contentId: this.contentId,
							type: 1,
							content: this.questionContent
						}
					})
					.then(response => {
						console.log(response)
						_this.commentAreaVisible = false;
						_this.getQuestionList()
					})
					.catch(err => {
						console.log(err);
					});
			}
		}
	}
</script>

<style scoped>
	.more-info-module {
		display: flex;
		justify-content: center;
		align-items: center;
		background: #F5FAFF;
		border-radius: 8upx;
		height: 74upx;
		font-family: PingFangSC-Regular;
		font-size: 28upx;
		color: #005BAD;
		letter-spacing: 0;
		margin: 20upx 0;
	}

	.question-list-title {
		display: flex;
		align-items: center;
		height: 80upx;
		background-color: #F2F2F4;
		text-indent: 80upx;
	}
    .mask{
		position: fixed;
		top: 0;
		left: 0;
		bottom: 0;
		z-index:999;
		width:100%;
		height:100vh;
		background:rgba(0,0,0,0.4);
	}
	.comment-area {
		/* position: fixed;
		top: 0upx; */
		background-color: white;
		width: 670upx;
		padding: 0 40upx;
		height: 90upx;
	}

	.comment-input {
		background-color: #eee;
		height: 72upx;
		border-radius: 36upx;
		width: 480upx;
		text-indent: 36upx;
		font-size: 32upx;
	}

	.comment-btn {
		width: 160upx;
		height: 72upx;
		border-radius: 36upx;
		background-color: orange;
		color: white;
		display: flex;
		align-items: center;
		justify-content: center;
	}
</style>
